#{extends 'mainStage.html' /}

#{set title:'Entrer les résultats' /}
#{if candidatures}
<div class="post">
    <div class="post">
        <h2 class="post-title">
            Liste des candidatures pour le stage: ${stage.intitule}
        </h2>
         #{form @entrerResultat(params.get("stageId"))} 
           <table cellpadding="0" cellspacing="0" border="0" class="display" id="liste"> 
                <thead>
                    <tr>
                        <th>CIS Service</th>
                        <th>Nom</th>
                        <th>Prenom</th>	
                        <th>Grade</th>
                        <th>R&ocirc;le</th>
                        <th>Etat</th>
                        <th>R&eacute;sultats des candidats</th>			
                    </tr>
                </thead>		

                <tbody>
                    #{list items:candidatures, as:'candidature' }
                        <tr>
                            <td>${candidature.agent.cisService}</td>
                            <td><a href="@{candidats.detailCandid(candidature.id)}">${candidature.agent.nom}</a></td>
                            <td>${candidature.agent.prenom}</td>
                            <td>${candidature.agent.grade}</td>
                            <td>${candidature.role}</td>
                            <td>${candidature.etatCandid}</td>
                           
                            <td id="tdChange${candidature.id}">
                                #{if candidature.resultat}
                                	${candidature.resultat}
                                	<a href="#" onClick="afficherList(${candidature.id})">Modifier</a>
                                #{/if}
                                #{else}
                                <select id="resultat" name="resultat" onchange="saveResultat(${candidature.id}, this.options[this.selectedIndex].value)">
                                		<option>- - Choisir un r&eacute;sultat - -</option>
                                	#{list items:resultats, as:'resultat'}
                                		<option value="${resultat.id}">${resultat.res}</option>
                                	#{/list}
                                </select>
                                #{/else}
                            </td>
                    </tr>
                    #{/list}

                </tbody>
            </table>
            <br />
        #{/form}
    </div>
</div>    
#{/if}

#{else}
<div class="empty">
    <p>Aucune candidature pr&eacute;sente.</p>
</div>
#{/else}
<script>
function saveResultat(id, val){
	$('#tdChange'+id).load("/resultat/"+id+'&'+val)
}

function afficherList(id){
	document.getElementById("tdChange"+id).innerHTML='<select id="resultat" name="resultat" onchange="saveResultat('+id+', this.options[this.selectedIndex].value)" value=0><option value=0>- - Choisir un r&eacute;sultat - -</option>#{list items:resultats, as:"resultat"}<option value="${resultat.id}">${resultat.res}</option>#{/list}</select>'						        				   			
}
</script>
